<?php
$host = '127.0.0.1';
$user = 'root';
$pwd = 'root';
$dbname = 'msg';
$db = new mysqli($host, $user, $pwd, $dbname);

if($db->connect_errno <> 0 ){
	echo "链接失败";
	echo $db->connect_error;
	exit;
}

$db->query("SET NAMES UTF8");

$sql = "SELECT * FROM msgform ORDER BY id DESC;";

$mysqli_result = $db->query($sql);
if( $mysqli_result === false ){
	echo "SQL错误";
	exit;
}

$rows = [];
while( $xinxi = $mysqli_result->fetch_array( MYSQLI_ASSOC ) ){
	$rows[] = $xinxi;	
}

?>

<!DOCTYPE html>
<head>
	<meta charset="utf-8">
	<title>php message page</title>
	<style type="text/css">
		.wrap{
			margin: 20px auto;
			text-align: center;
			display: block;
		}
	/*	.add{
			overflow: hidden;
	    }
		.content{
			float: left;
		}
		.btn{
			float: right;
		}*/
		.user{
			margin: 0;
			text-align: left;
		}
		.msg{
			/*background: skyblue;*/
		}

	</style>
</head>

<body>
	<div class="wrap">
		<form action="save.php" method="post">
		<div class="add">
			<div style="display: block;">
				<textarea class="content" name="content" cols="80" rows="10"></textarea>
			</div>
			<input class="user" name="user" type="text">
            <input class="btn" type="submit" value='发表留言'>
		</div>
		</form>

		<?php
		foreach ($rows as $row){
		?>
		<div class="msg">
			<div>
				<span>  <?php echo $row['user']; ?>  </span>
				<span>  <?php echo date("Y-n-j H:i:s", $row['intime']); ?>  </span>
			</div>
			<div>
				<?php echo $row['content'];?>
			</div>
		</div>
	<?php
	}
	?>
	</div>
</body>
</html>